package com.runtime.hongyunmanage.config;


import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("http://localhost:8010") // 前端域名
                .allowedMethods("GET", "POST", "PUT", "DELETE")
                 .allowedHeaders("*")
                .allowCredentials(true);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/productimage/**")
                .addResourceLocations("classpath:/static/image/productimage/"); // 对应 upload.path 配置
        registry.addResourceHandler("/categoryimage/**")
                .addResourceLocations("classpath:/static/image/categoryimage/");

    }
}